/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.mwas.proteana.math.numerical;

import java.math.BigDecimal;

/**
 *
 * @author loskov
 */
public class PValue extends HypergeometricTest {

    public PValue(int population, int sample, int popSuccess, int sampSuccess) {
        super(population, sample, popSuccess, sampSuccess);
        calculate();
    }
    
    public PValue(BigDecimal population, BigDecimal sample, BigDecimal popSuccess, BigDecimal sampSuccess) {
        super(population, sample, popSuccess, sampSuccess);
        calculate();
    }
    
    
    private BigDecimal calculate() {
        result = BigDecimal.ZERO;
        BigDecimal currHypGeoValue;
        BigDecimal xTemp = sampSuccess.abs();
        for(int i = sampSuccess.intValue(); i <= sample.intValue(); i++) {
            currHypGeoValue = new HypergeometricTest(population, sample, popSuccess, xTemp).getResult();
            result = result.add(currHypGeoValue);
            xTemp = xTemp.add(BigDecimal.ONE);
        }
        
        return result;
    }
    

}
